<?php

/**
 * Created by PhpStorm.
 * User: wuzhenlong
 * Date: 2017/9/15
 * Time: 下午7:46
 */
class ZL_Controller extends CI_Controller{
    //网站标题前缀
    protected $site_title = '期大圣';

    public function __construct(){
        parent::__construct();
        $this->load->helper('url','security');
        $this->load->library('session');
        $this->load->library('user_agent');
    }

    protected function check_user_login($type = 'controller'){
        switch ($type){
            case 'controller':
                if ($this->session->user_login == false){
                    $url = site_url('home/login');
                    exit("<meta http-equiv='Refresh' content='0;URL=$url'>");
                }
                break;
            case 'model':
                if ($this->session->user_login == false){
                    return false;
                }else{
                    return true;
                }
                break;
        }
    }

    //返回json编码
    protected function return_json($code = '0',$msg = ''){
        $json_arr = array('code'=>$code,'msg'=>$msg);
        return json_encode($json_arr);
    }

    //展示消息
    protected function show_message($type = 'success',$message = '操作成功',$link = '/index.php/admin_lhz_123/admin',$btn_title='点击返回'){
        $data['message'] = $message;
        $data['href'] = $link;
        $data['btnTitle'] = $btn_title;
        switch ($type){
            case 'success':
                $data['states'] = '&#xe616;';
                break;
            case 'fail':
                $data['states'] = '&#x1006;';
                break;
        }
        $this->load->view('errors/show_message.html',$data);
    }
}